package IU;

import Entidades.Localidad;
import Entidades.Operario;
import Entidades.Operariorol;
import java.util.List;
import java.util.Vector;
import javax.swing.JOptionPane;
import utiles.Validador;
import Controladores.CtrlAMBOperario;
import Controladores.CtrlTipodocumento;
import Controladores.CtrlOperariorol;
import Controladores.CtrlSeguridadusr;
import Controladores.CtrlUsuario;
import Entidades.Seguridadusr;
import Entidades.Usuario;
import java.util.Collection;
import java.util.ArrayList;

/**
 *
 * @author  
 * 
 * 
 */
public class ABMUsuario extends javax.swing.JFrame {

    String fechaAlta, fechaBaja, oper;
    String numerodoc;
    Operario operario;
    TablaPersonalizada tableModel;
    CtrlAMBOperario controladorop;
    CtrlTipodocumento controladortd;
    CtrlOperariorol controladoroprol;
    CtrlUsuario controladorusr;
    CtrlSeguridadusr ctrlseguridad;
    Operariorol or;
    Usuario u;
    Validador validador;
    private List listao, listaoprol, listau;
    List<Operario> aux = null;
    //listao lista de operarios activos que no tienen fecha de baja
    //listau lista de usuarios activos que not tienen fecha de baja que muestra los mismos datos que operario pero sale de usuario
    //acá ver si puedo hacer lo mismo con pais provincia traer la collection de provincia
    Collection<Localidad> localidadesCollection = new ArrayList<Localidad>();
    int idoperariosel;
    Operario ope;
    Operariorol oprol;

    public ABMUsuario(String o) {
        initComponents();
        oper = o;
        jTextFieldUsuario2.setText(oper);
        //    jTextFieldUsuario3.setText(oper);
        //  jTextFieldUsuario4.setText(oper);
        controladorop = new CtrlAMBOperario();

        controladortd = new CtrlTipodocumento();

        controladoroprol = new CtrlOperariorol();
        controladorusr = new CtrlUsuario();
        ctrlseguridad = new CtrlSeguridadusr();
        //alta
        cargarTablaOperarios();
        cargarTablaUsuarios();
        //fin alta
        //consultar
        cargarComboUsuarios();
//        //fin consultar
//        //modificar
//        cargarTabla();//ojo que está cargando el primero
//        cargarTipoDocumento1();
//        cargarComboEstadoPersona1();
//        cargarComboPaises1();
//        cargarComboProvincias1();
//        cargarComboLocalidades1();

    }
    //este no???

    public void cargarComboUsuarios() {
        try {
            listau = controladorusr.buscarTodosUsuario();
            //   System.out.println("tamaño de la lista de usuarios " + listau.size());
        } catch (Exception e) {
        }
        jComboBoxNombreUsuario.removeAllItems();
        for (int i = 0; i < listau.size(); i++) {
            Vector fila = new Vector();
            Usuario usuario = (Usuario) listau.get(i);
            fila.add(usuario.getNombre());
            jComboBoxNombreUsuario.addItem(fila.get(0));
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        GestorPesajeJpaPU2EntityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("GestorPesajeJpaPU2").createEntityManager();
        usuarioQuery = java.beans.Beans.isDesignTime() ? null : GestorPesajeJpaPU2EntityManager.createQuery("SELECT u FROM Usuario u");
        usuarioList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : usuarioQuery.getResultList();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel14 = new javax.swing.JLabel();
        jTextFieldnombre = new javax.swing.JTextField();
        jTextFieldtipoDoc = new javax.swing.JTextField();
        jTextFieldapellido = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jTextFieldnombreusuario = new javax.swing.JTextField();
        jPasswordFieldcontrasenia = new javax.swing.JPasswordField();
        jPasswordFieldrepetircontrasenia = new javax.swing.JPasswordField();
        jLabel4 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jButtonGuardar = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jTextFieldtextoseguridad = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jTextFieldnroDoc = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTableOperarios = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTableUsuarios = new javax.swing.JTable();
        jPanel4 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jPasswordFieldcontrasenia1 = new javax.swing.JPasswordField();
        jPasswordFieldrepetircontrasenia1 = new javax.swing.JPasswordField();
        jLabel5 = new javax.swing.JLabel();
        jTextFieldnombreusuario1 = new javax.swing.JTextField();
        modificar = new javax.swing.JButton();
        eliminar = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane5 = new javax.swing.JScrollPane();
        ButtBuscar = new javax.swing.JPanel();
        jTextFieldNombreListar = new javax.swing.JTextField();
        jLabelDniCon = new javax.swing.JLabel();
        jLabelTelCon = new javax.swing.JLabel();
        jTextFieldTipoDocu = new javax.swing.JTextField();
        jButtonBuscarCon = new javax.swing.JButton();
        jLabelDireccionCon = new javax.swing.JLabel();
        jTextFieldnrodoc = new javax.swing.JTextField();
        jLabelApellidoCon = new javax.swing.JLabel();
        jComboBoxNombreUsuario = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        jTextFieldApellido = new javax.swing.JTextField();
        jButtonSalir = new javax.swing.JButton();
        jPanel7 = new javax.swing.JPanel();
        jTextFieldUsuario2 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Gestionar Usuarios - Sistema Gestor de Pesaje para Bodegas");

        jTabbedPane1.setForeground(new java.awt.Color(102, 0, 102));
        jTabbedPane1.setFont(new java.awt.Font("Segoe UI", 3, 12));

        jLabel14.setFont(new java.awt.Font("Segoe UI", 1, 11));
        jLabel14.setText("Tipo Documento:");

        jTextFieldnombre.setEditable(false);
        jTextFieldnombre.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        jTextFieldtipoDoc.setEditable(false);
        jTextFieldtipoDoc.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        jTextFieldapellido.setEditable(false);
        jTextFieldapellido.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        jLabel16.setFont(new java.awt.Font("Segoe UI", 1, 11));
        jLabel16.setText("Apellido Operario:");

        jLabel18.setFont(new java.awt.Font("Segoe UI", 1, 11));
        jLabel18.setText("Nombre Operario:");

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED), "Ingrese Datos de Usuario", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI", 3, 11), new java.awt.Color(102, 0, 102))); // NOI18N

        jTextFieldnombreusuario.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        jPasswordFieldcontrasenia.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        jPasswordFieldrepetircontrasenia.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        jLabel4.setFont(new java.awt.Font("Segoe UI", 1, 11));
        jLabel4.setText("Nombre Usuario:");

        jLabel2.setFont(new java.awt.Font("Segoe UI", 1, 11));
        jLabel2.setText("Contraseña:");

        jLabel10.setFont(new java.awt.Font("Segoe UI", 1, 11));
        jLabel10.setText("Repetir Contraseña:");

        jLabel1.setFont(new java.awt.Font("Segoe UI", 1, 11));
        jLabel1.setForeground(new java.awt.Color(204, 0, 0));
        jLabel1.setText("Ingrese solo caracteres");

        jButtonGuardar.setFont(new java.awt.Font("Segoe UI", 3, 12));
        jButtonGuardar.setForeground(new java.awt.Color(102, 0, 102));
        jButtonGuardar.setText("Guardar");
        jButtonGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGuardarActionPerformed(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel6.setText("Clave Seguridad: ");

        jTextFieldtextoseguridad.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        jLabel8.setForeground(new java.awt.Color(204, 0, 0));
        jLabel8.setText("*");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel5Layout.createSequentialGroup()
                            .addComponent(jLabel6)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(jTextFieldtextoseguridad))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel5Layout.createSequentialGroup()
                            .addComponent(jLabel10)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(jPasswordFieldrepetircontrasenia, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel4))
                        .addGap(24, 24, 24)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPasswordFieldcontrasenia, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextFieldnombreusuario, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 483, Short.MAX_VALUE)
                        .addComponent(jButtonGuardar)
                        .addGap(31, 31, 31))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel1)
                        .addContainerGap())))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldnombreusuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jPasswordFieldcontrasenia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel10)
                            .addComponent(jPasswordFieldrepetircontrasenia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(jTextFieldtextoseguridad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButtonGuardar)))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(56, 56, 56)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jLabel8))))
                .addContainerGap(23, Short.MAX_VALUE))
        );

        jLabel15.setFont(new java.awt.Font("Segoe UI", 1, 11));
        jLabel15.setText("Nro Documento:");

        jTextFieldnroDoc.setEditable(false);
        jTextFieldnroDoc.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        jTableOperarios.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        jTableOperarios.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Apellido", "Nombre", "Area", "Cargo", "Rol"
            }
        ));
        jTableOperarios.setFillsViewportHeight(true);
        jTableOperarios.setMinimumSize(new java.awt.Dimension(55, 55));
        jTableOperarios.setPreferredSize(new java.awt.Dimension(200, 42));
        jTableOperarios.setRowHeight(14);
        jTableOperarios.getTableHeader().setResizingAllowed(false);
        jTableOperarios.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableOperariosMouseClicked(evt);
            }
        });
        jScrollPane4.setViewportView(jTableOperarios);

        jScrollPane1.setViewportView(jScrollPane4);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 832, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(159, 159, 159)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel16)
                                .addGap(18, 18, 18)
                                .addComponent(jTextFieldapellido, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel14)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jTextFieldtipoDoc, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel18)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldnombre, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel15)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jTextFieldnroDoc, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(36, 36, 36)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16)
                    .addComponent(jTextFieldapellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel18)
                    .addComponent(jTextFieldnombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel14)
                        .addComponent(jTextFieldtipoDoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel15)
                        .addComponent(jTextFieldnroDoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(26, 26, 26)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(32, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Alta Usuario", jPanel1);

        jScrollPane2.setAutoscrolls(true);

        jTableUsuarios.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Apellido", "Nombre", "Cargo", "Rol", "Area"
            }
        ));
        jTableUsuarios.setAutoscrolls(false);
        jTableUsuarios.setFillsViewportHeight(true);
        jTableUsuarios.setMinimumSize(new java.awt.Dimension(55, 55));
        jTableUsuarios.setPreferredSize(new java.awt.Dimension(200, 42));
        jTableUsuarios.setRowHeight(14);
        jTableUsuarios.getTableHeader().setResizingAllowed(false);
        jTableUsuarios.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableUsuariosMouseClicked(evt);
            }
        });
        jScrollPane3.setViewportView(jTableUsuarios);

        jScrollPane2.setViewportView(jScrollPane3);

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED), "Cambio de Clave", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI", 3, 12), new java.awt.Color(102, 0, 102))); // NOI18N

        jLabel3.setFont(new java.awt.Font("Segoe UI", 1, 11));
        jLabel3.setText("Contraseña:");

        jLabel11.setFont(new java.awt.Font("Segoe UI", 1, 11));
        jLabel11.setText("Repetir Contraseña:");

        jPasswordFieldcontrasenia1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        jPasswordFieldrepetircontrasenia1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 58, Short.MAX_VALUE)
                        .addComponent(jPasswordFieldcontrasenia1, javax.swing.GroupLayout.PREFERRED_SIZE, 231, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel11)
                        .addGap(18, 18, 18)
                        .addComponent(jPasswordFieldrepetircontrasenia1, javax.swing.GroupLayout.DEFAULT_SIZE, 231, Short.MAX_VALUE)))
                .addContainerGap(118, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jPasswordFieldcontrasenia1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(jPasswordFieldrepetircontrasenia1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(165, 165, 165))
        );

        jLabel5.setFont(new java.awt.Font("Segoe UI", 1, 11));
        jLabel5.setText("Nombre Usuario:");

        jTextFieldnombreusuario1.setEditable(false);
        jTextFieldnombreusuario1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        modificar.setFont(new java.awt.Font("Segoe UI", 3, 12));
        modificar.setForeground(new java.awt.Color(102, 0, 102));
        modificar.setText("Modificar");
        modificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                modificarActionPerformed(evt);
            }
        });

        eliminar.setFont(new java.awt.Font("Segoe UI", 3, 12));
        eliminar.setForeground(new java.awt.Color(102, 0, 102));
        eliminar.setText("Eliminar");
        eliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                eliminarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jLabel5)
                .addGap(32, 32, 32)
                .addComponent(jTextFieldnombreusuario1, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(520, Short.MAX_VALUE))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 491, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 21, Short.MAX_VALUE)
                .addComponent(modificar)
                .addGap(18, 18, 18)
                .addComponent(eliminar)
                .addGap(180, 180, 180))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(modificar)
                        .addComponent(eliminar))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 123, Short.MAX_VALUE)
                        .addGap(40, 40, 40)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(jTextFieldnombreusuario1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(62, 62, 62)
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(28, 28, 28)))
                .addGap(164, 164, 164))
        );

        jTabbedPane1.addTab("Modificar/Eliminar", jPanel2);

        jScrollPane5.setAutoscrolls(true);

        ButtBuscar.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED), "Datos del Usuario", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI", 1, 11), new java.awt.Color(102, 0, 102))); // NOI18N

        jTextFieldNombreListar.setEditable(false);
        jTextFieldNombreListar.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        jLabelDniCon.setFont(new java.awt.Font("Segoe UI", 1, 11));
        jLabelDniCon.setText("Nombre:");

        jLabelTelCon.setFont(new java.awt.Font("Segoe UI", 1, 11));
        jLabelTelCon.setText("Tipo Documento:");

        jTextFieldTipoDocu.setEditable(false);
        jTextFieldTipoDocu.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        jButtonBuscarCon.setFont(new java.awt.Font("Segoe UI", 3, 12));
        jButtonBuscarCon.setForeground(new java.awt.Color(102, 0, 102));
        jButtonBuscarCon.setMnemonic('B');
        jButtonBuscarCon.setText("Buscar");
        jButtonBuscarCon.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBuscarConActionPerformed(evt);
            }
        });

        jLabelDireccionCon.setFont(new java.awt.Font("Segoe UI", 1, 11));
        jLabelDireccionCon.setText("Nro Documento:");

        jTextFieldnrodoc.setEditable(false);
        jTextFieldnrodoc.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        jLabelApellidoCon.setFont(new java.awt.Font("Segoe UI", 1, 11));
        jLabelApellidoCon.setText("Nombre Usuario:");

        jComboBoxNombreUsuario.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        jComboBoxNombreUsuario.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jComboBoxNombreUsuarioMousePressed(evt);
            }
        });
        jComboBoxNombreUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxNombreUsuarioActionPerformed(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Segoe UI", 1, 11));
        jLabel7.setText("Apellido:");

        jTextFieldApellido.setEditable(false);
        jTextFieldApellido.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        javax.swing.GroupLayout ButtBuscarLayout = new javax.swing.GroupLayout(ButtBuscar);
        ButtBuscar.setLayout(ButtBuscarLayout);
        ButtBuscarLayout.setHorizontalGroup(
            ButtBuscarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ButtBuscarLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(ButtBuscarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButtonBuscarCon, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(ButtBuscarLayout.createSequentialGroup()
                        .addGroup(ButtBuscarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelDniCon)
                            .addComponent(jLabelApellidoCon)
                            .addComponent(jLabel7)
                            .addComponent(jLabelTelCon)
                            .addComponent(jLabelDireccionCon))
                        .addGap(33, 33, 33)
                        .addGroup(ButtBuscarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextFieldnrodoc, javax.swing.GroupLayout.DEFAULT_SIZE, 330, Short.MAX_VALUE)
                            .addComponent(jTextFieldTipoDocu, javax.swing.GroupLayout.DEFAULT_SIZE, 330, Short.MAX_VALUE)
                            .addComponent(jTextFieldApellido, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 330, Short.MAX_VALUE)
                            .addComponent(jTextFieldNombreListar, javax.swing.GroupLayout.DEFAULT_SIZE, 330, Short.MAX_VALUE)
                            .addComponent(jComboBoxNombreUsuario, javax.swing.GroupLayout.Alignment.TRAILING, 0, 330, Short.MAX_VALUE))))
                .addGap(65, 65, 65))
        );
        ButtBuscarLayout.setVerticalGroup(
            ButtBuscarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ButtBuscarLayout.createSequentialGroup()
                .addGroup(ButtBuscarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelApellidoCon)
                    .addComponent(jComboBoxNombreUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(ButtBuscarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jTextFieldApellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(ButtBuscarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelDniCon)
                    .addComponent(jTextFieldNombreListar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(ButtBuscarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelTelCon)
                    .addComponent(jTextFieldTipoDocu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(ButtBuscarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelDireccionCon)
                    .addComponent(jTextFieldnrodoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(26, 26, 26)
                .addComponent(jButtonBuscarCon)
                .addContainerGap(139, Short.MAX_VALUE))
        );

        jScrollPane5.setViewportView(ButtBuscar);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(226, Short.MAX_VALUE)
                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 531, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(131, 131, 131))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(46, 46, 46)
                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 330, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(194, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Listar Usuarios", jPanel3);

        jButtonSalir.setFont(new java.awt.Font("Segoe UI", 3, 12));
        jButtonSalir.setForeground(new java.awt.Color(102, 0, 102));
        jButtonSalir.setText("Salir");
        jButtonSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSalirActionPerformed(evt);
            }
        });

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED), "Ingrese Datos de Usuario", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI", 3, 11), new java.awt.Color(102, 0, 102))); // NOI18N

        jTextFieldUsuario2.setEditable(false);
        jTextFieldUsuario2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTextFieldUsuario2, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTextFieldUsuario2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(28, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 893, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(36, 36, 36)
                        .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(63, 63, 63))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 215, Short.MAX_VALUE)
                        .addComponent(jButtonSalir)
                        .addGap(24, 24, 24))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 600, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 450, Short.MAX_VALUE)
                .addComponent(jButtonSalir)
                .addGap(29, 29, 29))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-1217)/2, (screenSize.height-649)/2, 1217, 649);
    }// </editor-fold>//GEN-END:initComponents

    private void refresh() {
        jTextFieldnombreusuario.setText("");
        jTextFieldnombre.setText("");
        jTextFieldapellido.setText("");
        jTextFieldnombreusuario1.setText("");
        jTextFieldnroDoc.setText("");
        jTextFieldtipoDoc.setText("");
        jTextFieldnombreusuario.setText("");
        jPasswordFieldcontrasenia.setText("");
        jPasswordFieldrepetircontrasenia.setText("");
        jTextFieldtextoseguridad.setText("");

    }

private void jTableUsuariosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableUsuariosMouseClicked
    cargarCamposUsuarios();
}//GEN-LAST:event_jTableUsuariosMouseClicked

private void jButtonSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSalirActionPerformed
    this.dispose();
}//GEN-LAST:event_jButtonSalirActionPerformed

////////////////////////////ALTA USUARIO////////////////////////////
private void jButtonGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGuardarActionPerformed

    boolean usr = false;
    int ind = jTableOperarios.getSelectedRow();

    if (ind < 0) {
        JOptionPane.showMessageDialog(this, "Seleccione un Operario", "Alta Usuario", JOptionPane.INFORMATION_MESSAGE);
    } else {
        String nombreusuario = jTextFieldnombreusuario.getText();
        System.out.println("idoperariosel: " + idoperariosel);
        try {
            Usuario usuario1 = controladorusr.buscarUsuarioNombreUsuario(nombreusuario);
            JOptionPane.showMessageDialog(this, "El nombre de usuario no está disponible. Ingrese otro nombre de usuario", "Error", JOptionPane.ERROR_MESSAGE);
        } catch (Exception e) {
            usr = true;
        }
        List<Usuario> user = controladorusr.buscarUsuarioXOperario((Operariorol) listaoprol.get(ind));
        if (!user.isEmpty()) {

            JOptionPane.showMessageDialog(this, "El Operario seleccionado ya posee un usuario, debe eliminarlo para crear uno nuevo", "Error", JOptionPane.ERROR_MESSAGE);
        }else{
            if (usr == true) {
// Obtener el password
                char passArray[] = jPasswordFieldcontrasenia.getPassword();
                char repassArray[] = jPasswordFieldrepetircontrasenia.getPassword();
// Convertir el password a String
                String pass = new String(passArray);
                String repass = new String(repassArray);

                if (verificar(nombreusuario, pass, repass)) {
//                //////////////////////////PARA INCLUIR LA FECHA ACTUAL COMO FECHA DE ALTA ////////////
//                Date fechaActual = new Date();
//                String fecha = fechaActual.toString();
//
//                Calendar calendar = Calendar.getInstance();
//
//                int dia = calendar.get(Calendar.DAY_OF_MONTH);   //dia del mes
//                int mescal = calendar.get(Calendar.MONTH);  //mes, de 0 a 11
//                //IF MES MENOR QUE 10 CONCATENAR UN CERO ADELANTE
//                mescal = mescal + 1;
//                int anio = calendar.get(Calendar.YEAR);  //año
//                String diacalendar = String.valueOf(dia);
//                String mescalendar = String.valueOf(mescal);
//                if (mescal < 10) {
//                    mescalendar = "0" + String.valueOf(mescal);
//                    System.out.println("mescalendar es:" + mescal);
//                }
//                String aniocalendar = String.valueOf(anio);
//                fechaAlta = diacalendar + "/" + mescalendar + "/" + aniocalendar;
                    fechaAlta = Validador.getInstance().obtenerFechaSistema();
                    System.out.println("La fecha de hoy es: " + fechaAlta);
                    ////////////////////////////////////////////////////////////////////////////////////
                    fechaBaja = "";
                    ////////////Operariorol////////////
                    //Analia: comente lo que está a continuacion porque me parece que no es necesario
//                try {
//                    listaoprol = controladoroprol.buscarTodosOperariorol();
//                } catch (Exception e) {
//                    System.out.println(e);
//                }
//                for (int a = 0; a < listaoprol.size(); a++) {
//                    oprol = (Operariorol) listaoprol.get(a);
//                    if (oprol.getOperario().equals(ope)) {
//                        System.out.println("encontro el id igual");
//                    }
//                    System.out.println("fechafin es: " + oprol.getFechafin());
//                }
//                try {
//                    ope = controladorop.buscarOperario_X_idOperario(idoperariosel);
//                    System.out.println("trajo el operario x id");
//                } catch (Exception e) {
//                    System.out.println(e);
//                    System.out.println("No trajo el operario x id");
//                }

                    ////////////////////////////////
                    String passencriptado = encriptar(pass);
                    Usuario us = new Usuario();
                    Seguridadusr seguridadu = new Seguridadusr();
                    String textos = jTextFieldtextoseguridad.getText();
                    us.setNombre(nombreusuario);
                    us.setContrasenia(passencriptado);
                    us.setFechaalta(fechaAlta);
                    us.setFechabaja(fechaBaja);
                    us.setOperariorol((Operariorol) listaoprol.get(ind));



                    try {
                        controladorusr.guardarUsuario(us);


                        JOptionPane.showMessageDialog(this, "El Usuario ha sido guardado exitosamente!", "Alta", JOptionPane.INFORMATION_MESSAGE);
                    } catch (Exception e) {
                        System.out.println("no guardó el usuario");
                    }
                    seguridadu.setIdusuario(us);
                    seguridadu.setOperariorol(us.getOperariorol());
                    seguridadu.setTextoseguro(textos);
                    ctrlseguridad.guardar(seguridadu);
                    refresh();
                    cargarTablaUsuarios();

                }
            }
        }
    }
refresh();
}//GEN-LAST:event_jButtonGuardarActionPerformed

//////////////MODIFICAR OPERARIO/////////////////////////
    private void actualizarCombo(List lista1) {
        jComboBoxNombreUsuario.removeAllItems();
        for (int i = 0; i < lista1.size(); i++) {
            Vector fila = new Vector();
            Usuario usuario = (Usuario) lista1.get(i);
            fila.add(usuario.getNombre());
            jComboBoxNombreUsuario.addItem(fila.get(0));
        }
    }

private void modificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_modificarActionPerformed
    int ind = jTableUsuarios.getSelectedRow();
    if (ind < 0) {
        JOptionPane.showMessageDialog(this, "Debe seleccionar un Usuario para modificar!", "Modificar Usuario", JOptionPane.INFORMATION_MESSAGE);
    } else {
        // Obtener el password
        char passArray[] = jPasswordFieldcontrasenia1.getPassword();
        char repassArray[] = jPasswordFieldrepetircontrasenia1.getPassword();
// Convertir el password a String
        String pass = new String(passArray);
        String repass = new String(repassArray);
        if (verifica(pass, repass)) {
            //si los datos ingresados por el usuario son correctos, crea un usuario con los datos de entrada
            ///////////////////
            try {
                String passencriptado = encriptar(pass);
                System.out.println("pass enc" + passencriptado);
                u.setContrasenia(pass);
                controladorusr.modificarUsuario(u);
                JOptionPane.showMessageDialog(this, "Modificación realizada", "Modificar Usuarios", JOptionPane.INFORMATION_MESSAGE);
                cargarTablaUsuarios();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            //////////////////////////
        }
        limpiar();
    }
}//GEN-LAST:event_modificarActionPerformed
    private void cargarCampos() {
        //apellido nombre cuil, tipodoc, nro doc
        int fila = jTableOperarios.getSelectedRow();
        //Operario opera = new Operario();
        //  Operariorol operariorol = new Operariorol();
        or = (Operariorol) listaoprol.get(fila);
        //   operariorol = (Operariorol) listaoprol.get(fila);
        jTextFieldapellido.setText(or.getOperario().getApellido());
        jTextFieldnombre.setText(or.getOperario().getNombre());
        jTextFieldtipoDoc.setText(or.getOperario().getTipodocumento().getNombretipo());
        jTextFieldnroDoc.setText(String.valueOf(or.getOperario().getNumerodocumento()));

        idoperariosel = or.getIdoperariorol();
    }

    private void cargarCamposUsuarios() {
        //apellido nombre cuil, tipodoc, nro doc
        int fila = jTableUsuarios.getSelectedRow();
        //Operario opera = new Operario();
        //  Operariorol operariorol = new Operariorol();
        u = (Usuario) listau.get(fila);

        //   operariorol = (Operariorol) listaoprol.get(fila);
        if((u.getFechabaja().isEmpty())|| (u.getFechabaja().equals(""))){
        jTextFieldnombreusuario1.setText(u.getNombre());
//        jTextFieldnombre.setText(or.getIdoperario().getNombre());
//        jTextFieldtipoDoc.setText(or.getIdoperario().gettipodocumento().getNombretipodocumento());
//        jTextFieldnroDoc.setText(or.getIdoperario().getNumerodocumento());
//
//        idoperariosel = or.getIdoperariorol();
    }else{
         JOptionPane.showMessageDialog(this, "El Operario seleccionado no posee usuario!", "Atención", JOptionPane.ERROR_MESSAGE);
    }
    }

    private void cargarTablaOperarios() {
        List aux1 = null;
        String[] encabezados = new String[5];
        encabezados[0] = "Apellido";
        encabezados[1] = "Nombre";
        encabezados[2] = "Area";
        encabezados[3] = "Cargo";
        encabezados[4] = "Rol";
        tableModel = new TablaPersonalizada(encabezados);
        jTableOperarios.setModel(tableModel);
        try {
            //listao = controladorop.buscarTodosOperario();
            listaoprol = controladoroprol.buscarTodosOperariorol();
            System.out.println("tamaño de listaoprol  1: " + listaoprol.size());
            for (int p = 0; p < listaoprol.size(); p++) {
                Operariorol este = (Operariorol) listaoprol.get(p);
                System.out.println("este " + este);
                System.out.println("este fecha alta " + este.getFechainicio());
                System.out.println("este fecha baja " + este.getFechafin());
                System.out.println("tamaño de listaoprol 2: " + listaoprol.size());
            }
            //  System.out.println("tamaño de listaoprol" + listaoprol.size());
            // for (int i = 0; i < listaoprol.size(); i++) {
            //   Operariorol operariorols = (Operariorol) listaoprol.get(i);
            // if (!operariorols.getFechaFin().equals("") ) {
            for (int j = 0; j < listaoprol.size(); j++) {
                System.out.println("tamaño de listaoprol 3: " + listaoprol.size());
                Operariorol operariosrol = (Operariorol) listaoprol.get(j);
                System.out.println("operariosrol :" + operariosrol);
                System.out.println("id del operol: " + operariosrol.getOperario());
                String fecha = operariosrol.getFechafin();
//                if (fecha.equals("")) {
//                    System.out.println("dentro del if");
//                    //       if (operarios.getIdoperario() == operariorols.getIdoperariorol()) {
                Vector fila = new Vector();
                fila.add(operariosrol.getOperario().getApellido());
                fila.add(operariosrol.getOperario().getNombre());
                fila.add(operariosrol.getArea().getNombreArea());
                fila.add(operariosrol.getCargo().getNombreCargo());
                fila.add(operariosrol.getRol().getNombreRol());

                tableModel.addRow(fila);
                System.out.println("id del operol: " + operariosrol.getOperario());
//                } else {
//                    System.out.println("fuera dle if");
//                }
            }
        } catch (Exception e) {
        }
    }

    private boolean esvalido(String fecha) {
        boolean ver = false;

        if (fecha.equals("")) {
            ver = true;
            JOptionPane.showMessageDialog(this, "La fecha es vacia!", "Error", JOptionPane.ERROR_MESSAGE);
        } else {
            ver = false;
        }
        return ver;
    }

    private void cargarTablaUsuarios() {
        String[] encabezados = new String[5];
        encabezados[0] = "Apellido";
        encabezados[1] = "Nombre";
        encabezados[2] = "Area";
        encabezados[3] = "Cargo";
        encabezados[4] = "Rol";

        tableModel = new TablaPersonalizada(encabezados);
        jTableUsuarios.setModel(tableModel);

        try {
            listau = controladorusr.buscarTodosUsuario();
            // nombre, contrasenia, fechaAlta, fechaBaja, idpersonarol;
            //    System.out.println("tamaño de listausuarios" + listau.size());

            for (int i = 0; i < listau.size(); i++) {
                Usuario us = (Usuario) listau.get(i);

                //  if (us.getFechabaja() == "") {
                //    System.out.println("en este comparó la fecha baja");
                Vector fila = new Vector();
                fila.add(us.getOperariorol().getOperario().getApellido());
                fila.add(us.getOperariorol().getOperario().getNombre());
                fila.add(us.getOperariorol().getArea().getNombreArea());
                fila.add(us.getOperariorol().getCargo().getNombreCargo());
                fila.add(us.getOperariorol().getRol().getNombreRol());
                tableModel.addRow(fila);
                //  }

            }
        } catch (Exception e) {
        }
    }

    private void limpiarCampos() {
        jTextFieldapellido.setText("");
        jTextFieldnombre.setText("");
        jTextFieldnombreusuario.setText("");
        jTextFieldnombreusuario1.setText("");
        jTextFieldnroDoc.setText("");
        jTextFieldtipoDoc.setText("");

    }

///////////////////ELIMINAR Usuario////////////////////////////////////////
private void eliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_eliminarActionPerformed
    int ind = jTableUsuarios.getSelectedRow();
    if (ind < 0) {
        JOptionPane.showMessageDialog(this, "Debe seleccionar un Usuario para eliminar!", "Eliminar Usuario", JOptionPane.INFORMATION_MESSAGE);
    } else {
        Usuario u = (Usuario) listau.get(ind);
        int rta = JOptionPane.showConfirmDialog(this, "Esta seguro de que desea ELIMINAR el Usuario:\n NombreUsuario = " + u.getNombre() + " ?", "Eliminar Usuario", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
        if (rta == 0) {
            try {
                fechaBaja = validador.getInstance().obtenerFechaSistema();
                u.setFechabaja(fechaBaja);
                controladorusr.modificarUsuario(u);
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this, "Se incluirá esta fecha como fecha de baja", "Eliminar Usuario", JOptionPane.INFORMATION_MESSAGE);
            }


            cargarTablaUsuarios();

            limpiarCampos();
        }
    }
}//GEN-LAST:event_eliminarActionPerformed

////////////////////LISTAR OPERARIO///////////////////////////////////////
    private void cargarComboCuil() {
        try {
            listao = controladorop.buscarTodosOperario();
            System.out.println("tamaño de la lista de operarios " + listao.size());
        } catch (Exception e) {
        }
        jComboBoxNombreUsuario.removeAllItems();
        for (int i = 0; i < listao.size(); i++) {
            Vector fila = new Vector();
            Operario operari = (Operario) listao.get(i);
            fila.add(operari.getCuil());
            jComboBoxNombreUsuario.addItem(fila.get(0));
        }
    }

//este busca el operario pero debe traer el operariorol con el id buscar en operariorol
//traer el operariorol con el idoperario
//    public void mostrarDatosOperario(Long idmioperario) {
//        Operariorol mioperariorol = null;
//        List listoprol;
//        try {
//            listoprol = controladoroprol.buscarTodosOperariorol();
//
//
//        } catch (Exception e) {
//        }
//        jComboBoxtipoDocumento.removeAllItems();
//        for (int i = 0; i < listatd.size(); i++) {
//            Vector fila = new Vector();
//            Tipodocumento tipo = (Tipodocumento) listatd.get(i);
//            fila.add(tipo.getNombretipodocumento());
//            jComboBoxtipoDocumento.addItem(fila.get(0));
//        }
//
//    }
//    
//    catch (Exception e
//
//    
//    
//
//    ) {
//
//
//
//    }
/////////////////LISTAR////////////////////
private void jTableOperariosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableOperariosMouseClicked
    cargarCampos();

}//GEN-LAST:event_jTableOperariosMouseClicked

private void jButtonBuscarConActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonBuscarConActionPerformed
    ///////////////
    System.out.println("");
    Usuario miusuario = null;
    Object esteusuario = jComboBoxNombreUsuario.getSelectedItem();
    String nombreusuario = esteusuario.toString();

    try {
        miusuario = controladorusr.buscarUsuarioNombreUsuario(nombreusuario);
        System.out.println("miusuario " + miusuario);
    } catch (Exception e) {
        JOptionPane.showMessageDialog(this, "El usuario ingresado no se ha encontrado.\n ", "Usuarios", JOptionPane.ERROR_MESSAGE);
    }
    if (miusuario != null) {

        jTextFieldApellido.setText(miusuario.getOperariorol().getOperario().getApellido());
        jTextFieldNombreListar.setText(miusuario.getOperariorol().getOperario().getNombre());
        jTextFieldTipoDocu.setText((miusuario.getOperariorol().getOperario().getTipodocumento()).getNombretipo().toString());
        jTextFieldnrodoc.setText(String.valueOf(miusuario.getOperariorol().getOperario().getNumerodocumento()));
    }
}//GEN-LAST:event_jButtonBuscarConActionPerformed

private void jComboBoxNombreUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxNombreUsuarioActionPerformed
}//GEN-LAST:event_jComboBoxNombreUsuarioActionPerformed

private void jComboBoxNombreUsuarioMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jComboBoxNombreUsuarioMousePressed
    limpiarCampos();
    cargarComboUsuarios();// TODO add your handling code here:
}//GEN-LAST:event_jComboBoxNombreUsuarioMousePressed
//////////////////LISTAR///////////////
//Ojo qeu no verifica bien el telefono. da error cuando se ingresa una letra.
//    private boolean verificar(String ape, String nom, String tipodoc, String nrodoc, String estadoper, String direccion, String pais, String provincia, String localidad, String codigopostal, String telefono1, String telefono2, String fechaAlta, String fechaBaja) {
//
//        boolean ver = false;
//        if (ape.equals("") || nom.equals("") || tipodoc.equals("") || nrodoc.equals("") || estadoper.equals("") || direccion.equals("") || pais.equals("") || provincia.equals("") || localidad.equals("") || codigopostal.equals("") || telefono1.equals("") || telefono2.equals("")) {
//            JOptionPane.showMessageDialog(this, "Por favor llene todos los campos!!!", "Error", JOptionPane.ERROR_MESSAGE);
//
//        } else if (!validador.getInstance().soloContieneLetras(ape)) {
//            JOptionPane.showMessageDialog(this, "Apellido invalido!!!", "Error", JOptionPane.ERROR_MESSAGE);
//
//        } else if (!validador.getInstance().soloContieneLetrasYEspacios(nom)) {
//            JOptionPane.showMessageDialog(this, "Nombre invalido!!!", "Error", JOptionPane.ERROR_MESSAGE);
//
//        } else if (!validador.getInstance().soloContieneNumeros(nrodoc)) {
//            JOptionPane.showMessageDialog(this, "Número de documento invalido!!!", "Error", JOptionPane.ERROR_MESSAGE);
//
////        } else if (!validador.getInstance().soloContieneNumerosYGuiones(cuil)) {
////            JOptionPane.showMessageDialog(this, "Cuil invalida!!!", "Error", JOptionPane.ERROR_MESSAGE);
//
//        } else if (!validador.getInstance().soloContieneLetrasYNumerosYEspacios(direccion)) {
//
//            JOptionPane.showMessageDialog(this, "Dirección invalido!!!", "Error", JOptionPane.ERROR_MESSAGE);
//
//        } else if (!validador.getInstance().esTelefonoValido(telefono1)) {
//            JOptionPane.showMessageDialog(this, "El valor ingresado para telefono1 es incorrecto!!!", "Error", JOptionPane.ERROR_MESSAGE);
//
//        } else if (!validador.getInstance().esTelefonoValido(telefono2)) {
//            JOptionPane.showMessageDialog(this, "El valor ingresado para telefono2 es incorrecto!!!", "Error", JOptionPane.ERROR_MESSAGE);
//        } else {
//            ver = true;
//        }
//        return ver;
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel ButtBuscar;
    private javax.persistence.EntityManager GestorPesajeJpaPU2EntityManager;
    private javax.swing.JButton eliminar;
    private javax.swing.JButton jButtonBuscarCon;
    private javax.swing.JButton jButtonGuardar;
    private javax.swing.JButton jButtonSalir;
    private javax.swing.JComboBox jComboBoxNombreUsuario;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabelApellidoCon;
    private javax.swing.JLabel jLabelDireccionCon;
    private javax.swing.JLabel jLabelDniCon;
    private javax.swing.JLabel jLabelTelCon;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPasswordField jPasswordFieldcontrasenia;
    private javax.swing.JPasswordField jPasswordFieldcontrasenia1;
    private javax.swing.JPasswordField jPasswordFieldrepetircontrasenia;
    private javax.swing.JPasswordField jPasswordFieldrepetircontrasenia1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTableOperarios;
    private javax.swing.JTable jTableUsuarios;
    private javax.swing.JTextField jTextFieldApellido;
    private javax.swing.JTextField jTextFieldNombreListar;
    private javax.swing.JTextField jTextFieldTipoDocu;
    private javax.swing.JTextField jTextFieldUsuario2;
    private javax.swing.JTextField jTextFieldapellido;
    private javax.swing.JTextField jTextFieldnombre;
    private javax.swing.JTextField jTextFieldnombreusuario;
    private javax.swing.JTextField jTextFieldnombreusuario1;
    private javax.swing.JTextField jTextFieldnroDoc;
    private javax.swing.JTextField jTextFieldnrodoc;
    private javax.swing.JTextField jTextFieldtextoseguridad;
    private javax.swing.JTextField jTextFieldtipoDoc;
    private javax.swing.JButton modificar;
    private java.util.List<Entidades.Usuario> usuarioList;
    private javax.persistence.Query usuarioQuery;
    // End of variables declaration//GEN-END:variables

//    private boolean verificar(String cuil) {
//        boolean ver = false;
//
//        if (cuil.equals("")) {
//            JOptionPane.showMessageDialog(this, "Por favor ingrese el cuil del operario!!!", "Error", JOptionPane.ERROR_MESSAGE);
//        } else if (!validador.getInstance().soloContieneNumerosYGuiones(cuil)) {
//            JOptionPane.showMessageDialog(this, "Cuil incorrecto: Ingrese números y guiones para cuil!!!", "Error", JOptionPane.ERROR_MESSAGE);
//        } else if (!repetidoOperario(cuil) == true) {
//            JOptionPane.showMessageDialog(this, "Error el numero de cuil pertenece a otro operario !!!", "Error", JOptionPane.ERROR_MESSAGE);
//        } else {
//            ver = true;
//        }
//
//        return ver;
//    }
//    private boolean repetidoOperario(String cuil) {
//        boolean estarepetido = false;
//        Operario operarc = new Operario();
//        try {
//            operarc = controladorop.buscarOperarioCuil(cuil);
//            estarepetido = true;
//            System.out.println("Encontró el cuil en un operario");
//        } catch (Exception e) {
//            estarepetido = false;
//            System.out.println("NO está repetido el cuil en otro operario");
//        }
//        return estarepetido;
//    }
    private boolean verificar(String nombre, String contrasenia, String repass) {
        boolean ver = false;
        if (nombre.equals("") || contrasenia.equals("") || repass.equals("")) {
            JOptionPane.showMessageDialog(this, "Debe completar todos los datos!", "Error", JOptionPane.ERROR_MESSAGE);
        } else if (!validador.getInstance().soloContieneLetras(nombre)) {
            JOptionPane.showMessageDialog(this, "El valor ingresado para nombre no es válido!", "Error", JOptionPane.ERROR_MESSAGE);
        } else if (!validador.getInstance().passwrd(contrasenia)) {
            JOptionPane.showMessageDialog(this, "La contraseña debe ser mayor de 8 caracteres y menor a 15!", "Error", JOptionPane.ERROR_MESSAGE);
            System.out.println("passwrd contrasenia");
        } else if (!validador.getInstance().repassword(contrasenia, repass)) {
            JOptionPane.showMessageDialog(this, "La contraseña y la repetición de contraseña no son iguales!", "Error", JOptionPane.ERROR_MESSAGE);
        } else {
            ver = true;
        }
        return ver;
    }//fin clase

    private boolean verifica(String contrasenia, String repass) {
        boolean ver = false;
        if (contrasenia.equals("") || repass.equals("")) {
            JOptionPane.showMessageDialog(this, "Debe completar todos los datos, la contraseña no debe tener números!", "Error", JOptionPane.ERROR_MESSAGE);
        } else if (!validador.getInstance().passwrd(contrasenia)) {
            JOptionPane.showMessageDialog(this, "La contraseña debe ser mayor de 8 caracteres y menor a 15!", "Error", JOptionPane.ERROR_MESSAGE);
            System.out.println("passwrd contrasenia");
        } else if (!validador.getInstance().repassword(contrasenia, repass)) {
            JOptionPane.showMessageDialog(this, "La contraseña y la repetición de contraseña no son iguales, Ingrese nuevamente contraseña y repetición de contraseña!", "Error", JOptionPane.ERROR_MESSAGE);
        } else {
            ver = true;
        }
        return ver;
    }//fin clase

    public String encriptar(String info_a_encriptar) {

        String abc1 = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ";
        //Variable que contendrá la información encriptada
        String info_encriptada = "";
        //variable
        Boolean cambio = false;
        //Bucle for mientras i sea menor al largo de la cadena a encriptar
        for (int i = 0; i < info_a_encriptar.length(); i++) {
            //Bucle mientras j sea menor al patron impuesto en la variable abc1
            for (int j = 0; j < abc1.length(); j++) {
                //Si la letra es igual a una de las letras del patrón.
                if (info_a_encriptar.charAt(i) == abc1.charAt(j)) {
                    //Cambiamos a true la variable boolean
                    cambio = true;
                    //Condicionales para no pasarse del total de letras del patrón.
                    if ((j == 24) || (j == 25) || (j == 26) || (j == 51) || (j == 52) || (j == 53)) {
                        //si el indice j es igual a estos límites
                        //Asignamos encriptando esta letra el valor del array abc1 de j menos 24
                        info_encriptada = info_encriptada + abc1.charAt(j - 24);
                    } else {
                        //Sino fuera así le asignamos el valor del array abc1 de j mas 3
                        info_encriptada = info_encriptada + abc1.charAt(j + 3);
                    }
                    //El valor de j lo ponemos a 53 y terminamos el bucle for
                    j = 53;
                }
            }
            //Si cambio es igual a false
            if (!cambio) {
                //Cargamos en la variable que contendrá el resultado el valor del caracter
                //de la info a encriptar
                info_encriptada = info_encriptada + info_a_encriptar.charAt(i);
            }
            //Damos a la variable boolean el valor false
            cambio = false;
        }
        //Si se termino de recorrer la palabra, frase o archivo enviado...
        //Damos a la variable original enviada a la función el valor de la variable
        //que contiene la encriptación.
        info_a_encriptar = info_encriptada;
        //Retornamos dicho valor.
        return info_a_encriptar;
    }

    private void limpiar() {
        jTextFieldnombreusuario1.setText("");
        jPasswordFieldcontrasenia1.setText("");
        jPasswordFieldrepetircontrasenia1.setText("");
    }
}
